package util;

import java.sql.Time;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    public static String getFormatTime(Date date){
        Date today = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(today);
        int currYear = c.get(Calendar.YEAR);
        c.setTime(date);
        DateFormat dateFormat;
        if(currYear == c.get(Calendar.YEAR)){
            dateFormat = new SimpleDateFormat("MM月dd日 HH:mm");
        }else {
            dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
        }
        return dateFormat.format(date);
    }

    public static String now(){
        Date d = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(d);
    }
}
